package com.play.ballen.home.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.LinearLayout
import android.widget.TextView
import com.play.ballen.R
import com.play.ballen.utils.UserInfoManager

class ReportDialogUtils(private val mContext: Context) {

    val dialog: Dialog = Dialog(mContext)
    private lateinit var contentView: View

    var valuesReportCallback: ((Int) -> Unit)? = null

    var valuesCopyCallback: ((String) -> Unit)? = null

    var valuesDeleteCallback: ((Int) -> Unit)? = null

    fun show(id:Int?,content:String?,phone:String?,delete:Boolean?) {
        if (!this::contentView.isInitialized) {

            contentView =
                LayoutInflater.from(mContext).inflate(R.layout.dialog_report, null)
            contentView.let {

                UserInfoManager.getUserInfo()?.phone?.let { it1 -> Log.d("xyp", "userphone=="+it1) }
                Log.d("xyp", "phone=="+phone)
                if(UserInfoManager.getUserInfo()?.phone == phone){
                    it.findViewById<LinearLayout>(R.id.ll_report).visibility=View.GONE
                }

                if(!delete!!){
                    it.findViewById<LinearLayout>(R.id.ll_delete).visibility=View.GONE
                }

                it.findViewById<TextView>(R.id.tv_cancel).setOnClickListener { btn ->
                    dialog.dismiss()
                }
                it.findViewById<LinearLayout>(R.id.ll_report).setOnClickListener { btn ->
                    if (id != null) {
                        valuesReportCallback?.invoke(id)
                    }
                    dialog.dismiss()
                }
                it.findViewById<LinearLayout>(R.id.ll_copy).setOnClickListener { btn ->
                    if (content != null) {
                        valuesCopyCallback?.invoke(content)
                    }
                    dialog.dismiss()
                }

                it.findViewById<LinearLayout>(R.id.ll_delete).setOnClickListener { btn ->
                    if (id != null) {
                        valuesDeleteCallback?.invoke(id)
                    }
                    dialog.dismiss()
                }


                val params = dialog.window?.attributes
                params?.gravity = Gravity.BOTTOM
                dialog.window?.attributes = params
                dialog.setContentView(it)
                dialog.setCanceledOnTouchOutside(false)
                dialog.window?.setLayout(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT
                )
                dialog.window?.setBackgroundDrawable(ColorDrawable())
            }
        }


        if (!dialog.isShowing) {
            dialog.show()
        }
    }

}